package com.qf.java2201.controller;

import com.qf.java2201.common.R;
import com.qf.java2201.pojo.User;
import com.qf.java2201.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author wxf
 * @Date 2022/4/25 15:16
 * <p>
 * * origins   允许的 跨域请求
 * * allowCredentials    允许  cookie
 **/

@RestController
@RequestMapping("/user")
//@CrossOrigin(origins = {"http://127.0.0.1:5500"}, allowCredentials = "true")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public R login(String username, String password) {
        User result = userService.login(username, password);
        R r = new R();
        if (result != null) {
            r.setCode(200);
            r.setMsg("登录成功");
            r.setData(result);
        } else {
            r.setMsg("登录失败");
            r.setCode(-200);
        }
        return r;
    }
}
